import Vue from "vue";
import Vuex from "vuex";
import VueRouter from "vue-router";
import vueStore from "./store";
import routes from "./routes";
import App from "./app.vue";
import VueI18n from 'vue-i18n';
import Lang from "i18n/lang.js";
import Directives from "directives/clickoutside.js";
import "./main.scss";

Vue.use(VueI18n);
Vue.use(VueRouter);
Vue.use(Vuex);

// 加载vuex store
const store = new Vuex.Store(vueStore);

// 配置路由
const router = new VueRouter({
    routes,
    //模拟浏览器返回顶部行为
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) { //通过返回按钮返回
            return savedPosition;
        } else {
            return {
                x: 0,
                y: 0
            };
        }
    }
});

// 国际化
// 将默认语言保存到localStorage中
const i18n = new VueI18n({
    locale: Lang.getLocale(),
    messages: Lang
})

router.beforeEach((to, from, next) => {
    document.title = `${ i18n.t("common.M001") }|${ i18n.t(to.meta.title) }`;
    next();
})

const app = new Vue({
    components: { App },
    store,
    router,
    i18n
}).$mount("#app");